import { ArrayMinSize, IsArray, IsInt, IsNotEmpty, Max, Min } from "class-validator";
import { Type } from "class-transformer";
import { BaseEntity } from "./BaseEntity";

export class Movie extends BaseEntity {
    @Type(() => String)
    @IsNotEmpty({ message: "电影名称不能为空" })
    public name: string;

    @IsNotEmpty({ message: "电影类型不可以为空" })
    @ArrayMinSize(1, { message: '电影类型至少有一个 ' })
    @IsArray({ message: '电影类型必须是数组' })
    @Type(() => String)
    public types: string[];

    @IsNotEmpty({ message: "上映地区不可以为空" })
    @ArrayMinSize(1, { message: '上映地区至少有一个 ' })
    @Type(() => String)
    public areas: string[]

    @IsNotEmpty({ message: '电影时长不能为空' })
    @IsInt({ message: "时长必须是整数" })
    @Min(1, { message: '时长至少为1分钟' })
    @Max(999999, { message: '时长过长 ' })
    @Type(() => Number)
    public timeLong: number

    @IsNotEmpty({ message: '是否热映不能为空' })
    @Type(() => Boolean)
    public isHot: boolean = false

    @IsNotEmpty({ message: '是否即将上映不能为空' })
    @Type(() => Boolean)
    public isComing: boolean = false

    @IsNotEmpty({ message: '是否经典不能为空' })
    @Type(() => Boolean)
    public isClassic: boolean = false

    @Type(() => String)
    public description?: string

    @Type(() => String)
    public poster?: string;

    /**
     *  # 将一个平面对象转换为一个Movie对象
     *  @param plainObject  
     *  @returns 
     */
    public static transform(plainObject: object): Movie {
        return super.baseTransform(Movie, plainObject)
    }
}